﻿using DataAccess.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XYD.DataAccess;
using XYD.Framework.Data;
using XYD.Framework.Data.Dapper;

namespace DataAccess.DAL
{
    public class RoleDAL : BaseDAL
    {
        public Role Get(int id)
        {
            return CONN_TopicSharing.Get<Role>(id);
        }

        public bool Insert(Role role)
        {
            return CONN_TopicSharing.Insert<Role>(role);
        }

        public bool Update(Role role)
        {
            return CONN_TopicSharing.Update<Role>(role);
        }

        /// <summary>
        /// 根据角色状态获取角色信息
        /// </summary> 
        /// <param name="state">-1：所有状态，0禁用状态，1启用状态</param>
        /// <returns></returns>
        public List<Role> GetRoles(int state = -1)
        {
            string sql = " select * from Role where 1=1 ";
            if (state == 1 || state == 0)
            {
                sql = " and state= " + state;
            }
             
            return CONN_TopicSharing.SQLQuery<Role>(sql, null).ToList();
        }
        public List<Role> List(int by_id)
        {
            List<Role> roles = new List<Role>();
            roles = CONN_TopicSharing.SQLQuery<Role>("select * from Role ", new { by_id = by_id }).ToList();

            return roles;
        }
        public List<Role> ListPage(string strWhere, string orderbys, int pagesize, int pageindex, out int count)
        {
            List<Role> roles = new List<Role>();
            if (string.IsNullOrEmpty(strWhere))
            {
                strWhere = " 1=1 ";
            }
         
            if (string.IsNullOrEmpty(orderbys))
                orderbys = "id";

            roles = CONN_TopicSharing.SQLPager<Role>("*", " Role", strWhere, "", "", orderbys, pagesize, pageindex, out count, null).ToList();

            return roles;
        }
    }
}
